package com.yzx.lifeassistants.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yzx.lifeassistants.R;
import com.yzx.lifeassistants.bean.JobInfo;

/**
 * @Description: 教务处通知列表适配器
 * @author: yzx
 * @time: 2016-3-11 下午8:02:51
 */
public class JobInfoAdapter extends BaseAdapter {

	private List<JobInfo> dataList;
	private JobInfo data;
	private LayoutInflater inflater;
	private ViewHolder holder;

	public JobInfoAdapter(Context context, List<JobInfo> dataList) {
		this.dataList = dataList;
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.item_job_list, parent,
					false);
			holder = new ViewHolder();
			holder.titleTV = (TextView) convertView
					.findViewById(R.id.item_job_title_tv);
			holder.dateTV = (TextView) convertView
					.findViewById(R.id.item_job_date_tv);
			holder.monthTV = (TextView) convertView
					.findViewById(R.id.item_job_month_tv);
			holder.timeTV = (TextView) convertView
					.findViewById(R.id.item_job_time_tv);
			holder.placeTV = (TextView) convertView
					.findViewById(R.id.item_job_palce_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		data = dataList.get(position);
		holder.titleTV.setText(data.getTitle());
		holder.placeTV.setText(data.getPlace());
		String time = data.getDate();
		holder.dateTV.setText(time.substring(time.indexOf("月") + 1,
				time.indexOf("日")));
		holder.dateTV.setText(time.substring(time.indexOf("月") + 1,
				time.indexOf("日")));
		holder.monthTV.setText(time.substring(0, time.indexOf("月")).replace(
				"年", "-"));
		holder.timeTV.setText(time);
		return convertView;
	}

	static class ViewHolder {
		TextView titleTV;// 内容
		TextView dateTV;// 日期
		TextView monthTV;// 月份
		TextView timeTV;// 时间
		TextView placeTV;// 举办地点
	}
}
